﻿using BIMBaseCS;
using BIMBaseCS.ApplicationService;
using BIMBaseCS.Attributes;
using BIMBaseCS.Core;
using BIMBaseCS.Geometry;
using BIMBaseCS.SolidCore;
using BIMBaseCS.UI;
using checc_baseTools.CaveMouth;
using checc_baseTools.CaveMouth.Entity;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Net.Sockets;
//二进制存储加的
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using BIMBaseCS.TrafficCS;

namespace checc_baseTools
{
    [BPExternalCommandAttribute(name = "DongKou")]
    public class DongKou : IBPFunctionCommand
    {
        public override void onExcute(BPCommandContext context)
        {
            #region 盖板涵换填
            //System.String strAppPath = BPApplication.singleton().getAppPath();

            //System.String strPic1 = strAppPath + "Support\\QDPicture\\concrete.jpg";
            //System.String strPic2 = strAppPath + "Support\\QDPicture\\grass_displacements.jpg";

            ////按尺寸贴图
            //BPMaterial material1 = new BPMaterial();
            //material1.name = "222";
            //material1.mapFile = strPic1;
            //material1.isValid = true;
            //material1.mapUnit = BPMaterialMapUnit.mRelative;
            //BPMaterial material2 = new BPMaterial();
            //material2.name = "111";
            //material2.mapFile = strPic2;
            //material2.isValid = true;
            //material2.mapUnit = BPMaterialMapUnit.mRelative;
            //List<GePoint3d> point3Ds = new List<GePoint3d>();

            ////下一层图素集合
            //List<BPGraphics> graphicsList = new List<BPGraphics>();
            //List<ReplacementData> placementData = new List<ReplacementData>
            //{
            //    new ReplacementData() {},
            //    //new ReplacementData() {},
            //    //new ReplacementData() {},
            //    //new ReplacementData() {},
            //};
            //for (int i = 0; i < 1; i++)
            //{
            //    placementData[i].Id = i;
            //    placementData[i].TotalNumberLayers = 1;
            //    //材质集合
            //    placementData[i].Materials = material1;
            //    if (i == 0)
            //    {
            //        placementData[i].EdgeThickeningDepth = 0.5;
            //        placementData[i].EdgeThickeningLength = 0.5;
            //    }
            //}

            //for (int i = 0; i < placementData.Count; i++)
            //{
            //    if (i == placementData.Count - 1)
            //    {
            //        BPGraphics swap = Replacement.create(placementData[i], 2, -0.01, 30, 30, 0.20, 0.90, 0.60); swap.save();
            //        //BPGraphics swap = Replacement.create(placementData[i], 2, 0, 30, 30); swap.save();
            //        //Tuple<List<BPGraphics>, List<GePoint3d>> swap = Replacement.create(graphicsList, point3Ds, placementData, 2, 0.05, -30, -30);
            //        //graphicsList = swap.Item1;
            //        //point3Ds = swap.Item2;
            //    }
            //    else
            //    {
            //        BPGraphics swap = Replacement.create(placementData[i], 2, -0.01, 30, 30, 0.20, 0.90, 0.60); swap.save();
            //        //BPGraphics swap = Replacement.create(placementData[i], 2, 0, 30, 30); swap.save();
            //        //Tuple<List<BPGraphics>, List<GePoint3d>> swap = Replacement.create(graphicsList, point3Ds, placementData, 2, 0.05, -30, -30);
            //        //graphicsList = swap.Item1;
            //        //point3Ds = swap.Item2;
            //    }
            //}
            ////Tuple<List<BPGraphics>, List<GePoint3d>> point3Ds2 = Swap.create(point3Ds1.Item1, point3Ds1.Item2, 2, 1.5, 50, 0, 0, 0.5, 0, 0, -2, -15, materialList);
            ////平移
            //GeTransform transform = GeTransform.create(0, 1000, 0);
            //foreach (var item in graphicsList)
            //{
            //    BPGraphics graphics = item;
            //    //BPGraphicUtil.transformPhysicalGraphics(ref graphics, transform);
            //    graphics.save();
            //}

            #endregion

            #region 洞口

            ////矩阵X,Y  圆锥不一致的半径 1:1000
            //GePoint3d X = new GePoint3d(1, 0, 0);
            //GePoint3d Y = new GePoint3d(Math.Tan(Math.PI * 75 / 180), 1, 0);
            ////矩阵变化
            //GeRotMatrix rotMatrix = TaperedSlope.CE单位矩阵(new GePoint3d(), X, Y);
            //GeTransform transform = GeTransform.create(rotMatrix, new GePoint3d());

            #region 跌水
            //HeadFallBase headFallBase = new HeadFallBase();
            //HeadFall headFall = new HeadFall(headFallBase, 2, 80);
            //BPGraphics graphics = headFall.CreateEntityModel();
            //graphics.save();
            #endregion

            #region 跌水井
            //SideDitchDropWellData sideDitchDropWellData = new SideDitchDropWellData();
            //List<BPGraphics> graphics = SideDitchDropWells.CreateSideDitchFallWellBody(sideDitchDropWellData, 2, 2, 120);

            //foreach (var item in graphics)
            //{
            //    item.save();
            //}
            #endregion

            #region 排水槽
            //GutterData gutterData = new GutterData();
            //List<BPGraphics> gutter = Gutter.CreateEntityModel(gutterData, 2, 0.25, 90);
            //foreach (var item in gutter)
            //{
            //    BPGraphics graphics = item;
            //    graphics.save();
            //}
            #endregion


            #endregion

            #region 正盖板
            //System.String strAppPath = BPApplication.singleton().getAppPath();

            //System.String strPic1 = strAppPath + "Support\\QDPicture\\BIMBase.png";
            //BPMaterial material2 = new BPMaterial();
            //material2.name = "adadas";
            //material2.mapFile = strPic1;
            //material2.isValid = true;
            //material2.mapUnit = BPMaterialMapUnit.mRelative;
            //CoverplateFiltrateInfo2M820 coverplateInfo = new CoverplateFiltrateInfo2M820();
            //var a = PrefabricatedPositiveCover2M8_20.layout_Cover(coverplateInfo);
            //ElementAttribute.SettingMaterial(a, material2);
            //OneNoOneP2M820 oneNoOneP = new OneNoOneP2M820();
            //TwoSteelbar2M820 twoPNoSteel = new TwoSteelbar2M820();
            //ThreeSteelbar2M820 threeSteelbar = new ThreeSteelbar2M820();
            //LayoutCover.layout(coverplateInfo, oneNoOneP, twoPNoSteel, threeSteelbar);
            //FourSteelbar6M058 fourSteelbar = new FourSteelbar6M058();
            //FiveSteelbar6M058 fiveSteelbar = new FiveSteelbar6M058();
            //SixSteelbarInfo4M6M8_20 sixSteelbar = new SixSteelbarInfo4M6M8_20();
            //SevenSteelbarInfo4M6M8_20 sevenSteelbar = new SevenSteelbarInfo4M6M8_20();

            //FrontCover.create(coverplateInfo, oneNoOneP, twoPNoSteel, threeSteelbar);
            //LayoutCover6M058.layout(coverplateInfo, oneNoOneP, twoPNoSteel, threeSteelbar, fourSteelbar, fiveSteelbar);
            //////LayoutCoverPlate6M058.layout(coverplateInfo, oneNoOneP, twoPNoSteel, threeSteelbar, fourSteelbar, fiveSteelbar, sixSteelbar, sevenSteelbar);
            //LayoutCover4M6M8_20.layout(coverplateInfo, oneNoOneP, twoPNoSteel, threeSteelbar, fourSteelbar, fiveSteelbar, sixSteelbar, sevenSteelbar);
            #endregion

            #region 斜盖板
            //SlopingCover.Create(new GePoint3d(), 30, 1000, -200, 500);
            #endregion

            #region 八字墙
            ////八字墙实例
            //CheccWingWallData checcWingWallData = new CheccWingWallData();
            //var wingWall = CheccWingWall.create(checcWingWallData, 99, 0, -135);
            //foreach (var item in wingWall.Item1)
            //{
            //    item.save();
            //}
            #endregion

            #region 锥坡
            TaperedSlopeData taperedSlope = new TaperedSlopeData();
            var coneSlope = TaperedSlope.createTaperedSlope(taperedSlope, 2, 2, 0.25, 45);
            foreach (var item in coneSlope.Item1)
            {
                item.save();
            }
            #endregion

        }
    }

    #region 测试数据
    [BPExternalCommandAttribute(name = "Helix")]
    public class Helix : IBPFunctionCommand
    {
        public override void onExcute(BPCommandContext context)
        {
            BPDocument doc = BPApplication.singleton().activeDocument;
            BPModel model = doc.modelManager.activeModel;

            List<GePoint3d> points = new List<GePoint3d>();
            List<GePoint3d> allPoints = new List<GePoint3d>();

            double angle = 1;
            double radius = 1000;
            double LeftHeight = 40000;
            double LeftPitch = 10000;
            double RightHeight = 15000;
            double RightPitch1 = 1500;
            double RightPitch2 = 4000;
            GePoint3d point3D;

            //求平面圆
            for (int i = 0; i < 360 / angle; i++)
            {
                GePoint3d p = Helper.Rotation(new GePoint3d(0, 0, 0), new GePoint3d(radius, 0, 0), radius, -(angle * i));
                point3D = new GePoint3d(p.x, p.y, p.z);
                points.Add(point3D);
            }
            double Proportion = radius * 2 / points.Count / radius * 2;
            points.Add(new GePoint3d(radius, 0, 0));


            double Left = 0;
            double Right = 0;
            int Leftnum = 1;
            int RightNum = 1;
            for (int i = 0; i <= LeftHeight / LeftPitch; i++)
            {
                for (int j = 0; j < points.Count; j++)
                {
                    //第一次从右向左上升
                    if (i == 0 && j <= 180)
                    {
                        point3D = new GePoint3d(points[j].x, points[j].y, Left);
                        allPoints.Add(point3D);
                        continue;
                    }
                    //第一次从左向右上升
                    else if (i == 0 && j > 180)
                    {
                        Right += RightPitch1 / 180.00 * (i + 1);
                        point3D = new GePoint3d(points[j].x, points[j].y, Right * Proportion);
                        allPoints.Add(point3D);
                        continue;
                    }
                    //从右向左上升
                    else if (j < 180)
                    {
                        if (j == 0)
                        {
                            Left = Right + (LeftPitch * i - Right) / 180.00 * Leftnum;
                            Leftnum++;
                            point3D = new GePoint3d(points[j + 1].x, points[j + 1].y, Left * Proportion);
                            allPoints.Add(point3D);
                        }
                        else
                        {
                            Left = Right + (LeftPitch * i - Right) / 180.00 * Leftnum;
                            Leftnum++;
                            point3D = new GePoint3d(points[j + 1].x, points[j + 1].y, Left * Proportion);
                            allPoints.Add(point3D);
                        }
                    }
                    //从左向右上升
                    else if (j >= 180)
                    {
                        if (j == points.Count - 1)
                        {
                            RightNum = 1;
                            Leftnum = 1;
                            break;
                        }
                        //最后一圈，螺距不同
                        else if (i == LeftHeight / LeftPitch)
                        {
                            Right = Left - (Left - RightHeight) / 180.00 * RightNum;
                            RightNum++;
                            point3D = new GePoint3d(points[j + 1].x, points[j + 1].y, Right * Proportion);
                            allPoints.Add(point3D);
                        }
                        else
                        {
                            Right = Left - (Left - (RightPitch1 + RightPitch2 * i)) / 180.00 * RightNum;
                            RightNum++;
                            point3D = new GePoint3d(points[j + 1].x, points[j + 1].y, Right * Proportion);
                            allPoints.Add(point3D);
                        }
                    }
                }
            }

            for (int i = 0; i < allPoints.Count - 1; i++)
            {
                Element_chain.Thread(allPoints[i], allPoints[i + 1]);
            }
        }
    }
    #endregion

}